<?php

//---------------------------Functions for hash-------------------------------//

function Scramble($dString) {
    $strOne = "";
    $strTwo = "";
    $i = 0;
    $x = 0;
    $dString = explode(" ", $dString);
    for ($x = 0; $x < count($dString); $x++) {
        $dStr = $dString[$x];
        srand((double) microtime() * 10000000);
        for ($i = 0; $i < strlen($dStr); $i++) {
            $strOne = rand(0, strlen($dStr) - 1);
            $strTwo = $dStr[$i];
            $dStr[$i] = $dStr[$strOne];
            $dStr[$strOne] = $strTwo;
        }
        $dReturn .= "" . $dStr;
    }
    return $dReturn;
}

function make_hash($length = 5) {
    $chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $chars .= hash('sha256', microtime(true)) . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
            . hash('sha256', microtime(true)) . 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $chars = Scramble($chars);
    $hash = '';
    for ($i = 0; $i < $length; $i++) {
        $hash .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
    }

    return $hash;
}
?>
